package com.shell.customer.accreditation.rx;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.shell.customer.accreditation.AccreditEvent;
import com.shell.customer.invitation.service.InvtCusService;
import com.shell.customer.po.CusInvt;
import com.shell.customer.po.CusOpt;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;

@Component
public class UpdateCustypeSubscriber extends OnErrorNotImplementedSubscriber<AccreditEvent> {
	@Autowired
	private InvtCusService invtCusService;

	public void onApplicationEvent(AccreditEvent event) {
		CusInvt cusInvt = new CusInvt();
		CusOpt cusOpt = event.getCusOpt();
		cusInvt.setInviteeId(cusOpt.getCusId());
		List<CusInvt> invts = this.invtCusService.selectByEntity(cusInvt);
		for (CusInvt invt : invts) {
			invt.setInviterId(event.getEntId());
			this.invtCusService.updateNotNull(invt);
		}
		event.getAccreditationVo().getCustomerC().setCusType(event.getCusType());
	}
}
